package com.atguigu.day17.work;

import java.util.Comparator;
import java.util.TreeSet;

public class Work1 {
    public static void main(String[] args) {
        System.out.println("按成绩和年龄排序:");
        TreeSet<Student> set = new TreeSet<>();
        set.add(new Student("张三", 20, 89.5));
        set.add(new Student("李四", 22, 89.5));
        set.add(new Student("王五", 21, 90.0));
        set.add(new Student("赵六", 19, 89.0));
        for (Student student : set) {
            System.out.println(student);
        }
        System.out.println("按照姓名排序");
        TreeSet<Student> all = new TreeSet<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o1.getName().compareTo(o2.getName());
            }
        });
        all.addAll(set);
        for (Student student : all) {
            System.out.println(student);
        }
    }
}
